package com.hcss.core.mvc.page;

import com.hcss.core.common.permissions.model.UserInfo;



/**
 * @ClassName: Page
 * @Description: TODO 用于JQUERY分页组件显示参数
 * @author lvfang
 * @date 2013-3-27 上午9:45:26
 * 
 */
public class Page {
	private int page = 1;

	private int rows = 10;

	private String sort;

	private String order;

	private UserInfo loginUser;

	/**
	 * @return the loginUser
	 */
	public UserInfo getLoginUser() {
		return loginUser;
	}

	/**
	 * @param loginUser
	 *            the loginUser to set
	 */
	public void setLoginUser(UserInfo loginUser) {
		this.loginUser = loginUser;
	}

	/**
	 * @return the sort
	 */
	public String getSort() {
		return sort;
	}

	/**
	 * @param sort
	 *            the sort to set
	 */
	public void setSort(String sort) {
		this.sort = sort;
	}

	/**
	 * @return the order
	 */
	public String getOrder() {
		return order;
	}

	/**
	 * @param order
	 *            the order to set
	 */
	public void setOrder(String order) {
		this.order = order;
	}

	public Page(UserInfo loginUser) {
		this.loginUser = loginUser;
	}

	public Page(UserInfo loginUser, int pageSize) {
		this.loginUser = loginUser;
		this.rows = pageSize;
	}

	public Page() {
	}

	public Page(int page, int rows) {
		this.page = page;
		this.rows = rows;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public int getStart() {
		return (page - 1) * rows;
	}

	public int getEnd() {
		return page * rows;
	}

	/**
	 * 转换分页
	 * 
	 * @param page
	 * @return
	 */
	public static Pager toPager(Page page) {
		Pager pager = new Pager();
		pager.setStartRow(page.getPage(), page.getRows());
		pager.setEndRow(page.getPage(), page.getRows());
		pager.setPageSize(page.getRows());
		pager.setSort(page.getSort());
		pager.setOrder(page.getOrder());
		pager.setLoginUser(page.getLoginUser());
		pager.setNext(page.getPage());
		return pager;
	}
}
